﻿-- =============================================
-- Author:		zengfei
-- Create date: 04m/18/2013
-- Description:	根据查询条件读取相应的销售单资料
-- =============================================
CREATE PROCEDURE [dbo].[Usp_SelectSalesByCondition]
	@p_SalesNo	varchar(30),
	@p_ReferenceNo	varchar(30),
	@p_CustomerNo		varchar(8),
	@p_Warehouse	int,
	@p_Employee		varchar(20),
	@p_EntryDate	datetime,
	@p_InvoiceStatus	bit
AS
select * 
	from SalesMaster 
	where (case when @p_SalesNo is null then 1 else (case when SalesNo = @p_SalesNo then 1 else 0 end) end) = 1 and
			(case when @p_ReferenceNo is null then 1 else (case when ReferenceNo = @p_ReferenceNo then 1 else 0 end) end) = 1 and
			(case when @p_CustomerNo is null then 1 else (case when CustomerNo = @p_CustomerNo then 1 else 0 end) end) = 1 and 
			(case when @p_Warehouse is null then 1 else (case when Warehouse = @p_Warehouse then 1 else 0 end) end) = 1 and 
			(case when @p_Employee is null then 1 else (case when Employee = @p_Employee then 1 else 0 end) end) = 1 and 
			(case when @p_EntryDate is null then 1 else (case when EntryDate = @p_EntryDate then 1 else 0 end) end) = 1